package com.quasar.hpatient.view.adapter;

import android.text.TextPaint;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.custommodel.BloodPressureTableItem;
import com.quasar.hpatient.model.custommodel.TemperatureTableItem;
import com.quasar.hpatient.utils.Spanny;

import java.util.List;

/**
 * author : 许建宏
 * Date: 2017/10/26 0026
 * View:血压adapter
 */

public class BloodPressureAdapter extends BaseMultiItemQuickAdapter<TemperatureTableItem, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public BloodPressureAdapter(List<TemperatureTableItem> data) {
        super(data);
        addItemType(TemperatureTableItem.HEAD, R.layout.widget_blood_head);
        addItemType(TemperatureTableItem.BODY, R.layout.widget_blood_pressure);
    }

    @Override
    protected void convert(BaseViewHolder helper, TemperatureTableItem item) {
        Spanny spanny = new Spanny();
        switch (helper.getItemViewType()) {
            case BloodPressureTableItem.BODY:
                //检测时间
                if (item.getLogTime() != null && item.getLogTime().length() > 0) {
                    helper.setText(R.id.tv_blood_time, item.getLogTime());
                }
                StringBuffer stringBuffer=new StringBuffer();
                stringBuffer.append(item.getLogValue()+"/");
                stringBuffer.append(item.getPaired());

                //血压低
                if (item.getPaired() != null) {
                    helper.setText(R.id.tv_val_low, stringBuffer.toString());
                }
                //级别
                String statsVal = "";
                TextView tv_stas=helper.getView(R.id.tv_stas);
                TextPaint tp = tv_stas.getPaint();
                switch (Integer.parseInt(item.getStats())) {

                    case 7:
                        statsVal = "单纯收缩期高血压";
                        spanny.append(statsVal, new ForegroundColorSpan(color(R.color.red)));
                        tp.setFakeBoldText(true);
                        break;
                    case 1:
                        statsVal = "低血压";
                        spanny.append(statsVal, new ForegroundColorSpan(color(R.color.red)));
                        tp.setFakeBoldText(true);
                        break;

                    case 2:
                        statsVal = "正常";
                        spanny.append(statsVal, new ForegroundColorSpan(color(R.color.btcolor)));
                        break;

                    case 3:
                        statsVal = "正常高值";//1级高血压(轻度)
                        spanny.append(statsVal, new ForegroundColorSpan(color(R.color.btcolor)));
                        tp.setFakeBoldText(true);
                        break;

                    case 4:
                        statsVal = "1级高血压(轻度)";
                        spanny.append(statsVal, new ForegroundColorSpan(color(R.color.red)));
                        tp.setFakeBoldText(true);
                        break;

                    case 5:
                        statsVal = "2级高血压(中度)";
                        spanny.append(statsVal, new ForegroundColorSpan(color(R.color.red)));
                        tp.setFakeBoldText(true);
                        break;

                    case 6:
                        statsVal = "3级高血压(重度)";
                        spanny.append(statsVal, new ForegroundColorSpan(color(R.color.red)));
                        tp.setFakeBoldText(true);
                        break;
                }
                tv_stas.setText(spanny);
        }

        helper.addOnClickListener(R.id.tv_val_low);
        helper.addOnLongClickListener(R.id.tv_val_low);
    }

    private int color(int value) {
        return MainAppliaction.getInstance().getResources().getColor(value);
    }
}
